﻿using System;
using System.ComponentModel;
using System.Windows.Forms;
using DevExpress.XtraEditors;

namespace Speedy
{
    public partial class frmMain : XtraForm
    {
        public frmMain()
        {
            InitializeComponent();
        }

        private void frmMain_FormClosed(object sender, FormClosedEventArgs e)
        {
            Config.GetConfig.Save();
        }

        private void barButtonItem4_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            using (frmPlasiyer pl = new frmPlasiyer())
            {
                pl.ShowDialog(this);
            }
        }

        private void barButtonItem5_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            using (frmArac arac = new frmArac())
            {
                arac.ShowDialog(this);
            }
        }

        private void barButtonItem6_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            using (frmRoute route = new frmRoute())
            {
                route.ShowDialog(this);
            }
        }

        private void barButtonItem7_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            using (frmPromosyon prm = new frmPromosyon())
            {
                prm.ShowDialog(this);
            }
        }

        private void barButtonItem8_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            using (frmStokPromosyon stk = new frmStokPromosyon())
            {
                stk.ShowDialog(this);
            }
        }

        private void barButtonItem9_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            using (frmCariPromosyon cari = new frmCariPromosyon())
            {
                cari.ShowDialog(this);
            }
        }

        private void barButtonItem10_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {

        }

        private void barButtonItem11_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {

        }

        private void barButtonItem12_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            using (frmVergi ver = new frmVergi())
            {
                ver.ShowDialog(this);
            }
        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            timer1.Stop();
            timer1.Enabled = false;
            backgroundWorker1.WorkerSupportsCancellation = true;
            backgroundWorker1.WorkerReportsProgress = true;
            backgroundWorker1.RunWorkerAsync();
        }

        private void frmMain_Load(object sender, EventArgs e)
        {
            if (Config.GetConfig.GetValue(CParams.Db) == null)
            {
                timer1.Stop();
                timer1.Enabled = false;
                frmAyarlar frm = new frmAyarlar();
                frm.ShowDialog();
                Application.Exit();
            }

            if (Config.GetConfig.GetValue(CParams.Db).IndexOf("V15") > -1)
            {

                timer1.Stop();
                timer1.Enabled = false;
                MessageBox.Show("Pogram V15 uyumlu değildir lütfen firmayı arayınız !");
                Application.Exit();
            }

            if (Config.GetConfig.GetValue(CParams.Db) != "MikroDB_V14_HUNKARGIDA")
            {
                timer1.Stop();
                timer1.Enabled = false;
                Application.Exit();
            }

            timer1.Interval = int.Parse(Config.GetConfig.GetValue(CParams.SenkTime, "10")) * 1000;
        }

        private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
        {
            Synchronizer sync = new Synchronizer();
            sync.EvrakAktar();
        }

        private void backgroundWorker1_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
        {
            timer1.Enabled = true;
            timer1.Start();
        }

        private void barButtonItem1_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            using (frmEvrakYonetim yon = new frmEvrakYonetim())
            {
                yon.ShowDialog(this);
            }
        }

        private void barButtonItem2_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            frmDosDizayn tsrm = new frmDosDizayn();
            tsrm.Show(this);
        }

        private void barButtonItem13_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {

        }

        private void barButtonItem14_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            using (frmAyarlar ayar = new frmAyarlar())
            {
                ayar.ShowDialog(this);
            }
        }

        private void barButtonItem15_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            using (frmCihazAyarlari ci = new frmCihazAyarlari())
            {
                ci.ShowDialog(this);
            }
        }

        private void barButtonItem16_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            using (Database db = new Database())
            {
                if (Config.GetConfig.GetValue(CParams.ProgramType, "WorkGroup") == "WorkGroup")
                {
                    db.CreateTable(false);
                }
                else
                    db.CreateTable(true);
            }
        }

    }
}
